package com.zonhar.autofeed.common.exception;

import com.zonhar.autofeed.common.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private final static Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 与传感器失去连接
     * @param ue
     * @return
     */
    @ResponseBody
    @ExceptionHandler(RaspberrypiException.class)
    public R globalException(RaspberrypiException ue){
        log.error("与树莓派失去连接: {}",ue.getMessage());
        return R.error(ue.getMessage());
    }

}
